package wildlife;

import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

public class post {
String post;
String username;
String date;

public String getDate() {
	return date;
}
public void setDate(String date) {
	this.date = date;
}
public String getPost() {
	return post;
}
public void setPost(String post) {
	this.post = post;
}



public String execute() throws SQLException, ParseException
{
	Date d=new Date();
	String dat=d.toString();
	d = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy").parse(dat);
	date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d);
	String query;
	HttpServletRequest request=ServletActionContext.getRequest();
	HttpSession session=request.getSession();
	String username=session.getAttribute("username")+"";
	System.out.println("username is "+username);
	System.out.println("post is :"+post);
	if(username.equals("admin"))
	{
		query="insert into notifications(notification,username,approved) values('"+post+"','"+username+"',1)";
	}
	else
	{
		query="insert into notifications(notification,username) values('"+post+"','"+username+"')";		
	}
	Connect c=new Connect();
	c.dml(query);
	return "success";
	
}
}
